from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-17 14:06:55.449810
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 17, Feb, 2021
Time: 14:07:00
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.2465
Nobs: 205.000 HQIC: -47.1153
Log likelihood: 2361.86 FPE: 1.91477e-21
AIC: -47.7054 Det(Omega_mle): 1.24726e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.466646 0.139072 3.355 0.001
L1.Burgenland 0.076617 0.071341 1.074 0.283
L1.Kärnten -0.216668 0.060301 -3.593 0.000
L1.Niederösterreich 0.131790 0.165736 0.795 0.427
L1.Oberösterreich 0.244335 0.145545 1.679 0.093
L1.Salzburg 0.209296 0.076743 2.727 0.006
L1.Steiermark 0.102283 0.103763 0.986 0.324
L1.Tirol 0.142068 0.069237 2.052 0.040
L1.Vorarlberg -0.009636 0.063258 -0.152 0.879
L1.Wien -0.132361 0.136688 -0.968 0.333
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.479134 0.168401 2.845 0.004
L1.Burgenland 0.012143 0.086385 0.141 0.888
L1.Kärnten 0.356416 0.073018 4.881 0.000
L1.Niederösterreich 0.120677 0.200687 0.601 0.548
L1.Oberösterreich -0.135131 0.176239 -0.767 0.443
L1.Salzburg 0.195373 0.092927 2.102 0.036
L1.Steiermark 0.210244 0.125646 1.673 0.094
L1.Tirol 0.142432 0.083838 1.699 0.089
L1.Vorarlberg 0.161095 0.076599 2.103 0.035
L1.Wien -0.529513 0.165514 -3.199 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.313904 0.061734 5.085 0.000
L1.Burgenland 0.108372 0.031668 3.422 0.001
L1.Kärnten -0.018407 0.026768 -0.688 0.492
L1.Niederösterreich 0.081264 0.073570 1.105 0.269
L1.Oberösterreich 0.284189 0.064608 4.399 0.000
L1.Salzburg -0.002859 0.034066 -0.084 0.933
L1.Steiermark -0.017544 0.046061 -0.381 0.703
L1.Tirol 0.086747 0.030734 2.823 0.005
L1.Vorarlberg 0.111891 0.028081 3.985 0.000
L1.Wien 0.058208 0.060676 0.959 0.337
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.225755 0.069928 3.228 0.001
L1.Burgenland -0.005883 0.035871 -0.164 0.870
L1.Kärnten 0.023643 0.030320 0.780 0.436
L1.Niederösterreich 0.043715 0.083334 0.525 0.600
L1.Oberösterreich 0.376030 0.073182 5.138 0.000
L1.Salzburg 0.088957 0.038587 2.305 0.021
L1.Steiermark 0.184440 0.052174 3.535 0.000
L1.Tirol 0.039772 0.034813 1.142 0.253
L1.Vorarlberg 0.092688 0.031807 2.914 0.004
L1.Wien -0.070978 0.068729 -1.033 0.302
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.518359 0.139652 3.712 0.000
L1.Burgenland 0.059772 0.071638 0.834 0.404
L1.Kärnten 0.017533 0.060553 0.290 0.772
L1.Niederösterreich -0.025683 0.166426 -0.154 0.877
L1.Oberösterreich 0.137191 0.146151 0.939 0.348
L1.Salzburg 0.058685 0.077062 0.762 0.446
L1.Steiermark 0.128558 0.104195 1.234 0.217
L1.Tirol 0.211486 0.069525 3.042 0.002
L1.Vorarlberg 0.025724 0.063522 0.405 0.686
L1.Wien -0.122224 0.137258 -0.890 0.373
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165837 0.098709 1.680 0.093
L1.Burgenland -0.012923 0.050635 -0.255 0.799
L1.Kärnten -0.008582 0.042800 -0.201 0.841
L1.Niederösterreich 0.116265 0.117634 0.988 0.323
L1.Oberösterreich 0.378851 0.103303 3.667 0.000
L1.Salzburg -0.020097 0.054470 -0.369 0.712
L1.Steiermark -0.021998 0.073648 -0.299 0.765
L1.Tirol 0.184938 0.049142 3.763 0.000
L1.Vorarlberg 0.046580 0.044899 1.037 0.300
L1.Wien 0.178251 0.097017 1.837 0.066
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.234648 0.126600 1.853 0.064
L1.Burgenland 0.059327 0.064942 0.914 0.361
L1.Kärnten -0.037549 0.054893 -0.684 0.494
L1.Niederösterreich -0.024089 0.150872 -0.160 0.873
L1.Oberösterreich -0.087254 0.132492 -0.659 0.510
L1.Salzburg 0.043673 0.069860 0.625 0.532
L1.Steiermark 0.391282 0.094457 4.142 0.000
L1.Tirol 0.482916 0.063027 7.662 0.000
L1.Vorarlberg 0.167815 0.057585 2.914 0.004
L1.Wien -0.229226 0.124430 -1.842 0.065
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081198 0.153385 0.529 0.597
L1.Burgenland 0.032553 0.078683 0.414 0.679
L1.Kärnten -0.076992 0.066507 -1.158 0.247
L1.Niederösterreich 0.266214 0.182793 1.456 0.145
L1.Oberösterreich -0.026788 0.160524 -0.167 0.867
L1.Salzburg 0.243155 0.084641 2.873 0.004
L1.Steiermark 0.138894 0.114442 1.214 0.225
L1.Tirol 0.058968 0.076362 0.772 0.440
L1.Vorarlberg 0.057356 0.069769 0.822 0.411
L1.Wien 0.229660 0.150756 1.523 0.128
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.586755 0.082527 7.110 0.000
L1.Burgenland -0.037060 0.042334 -0.875 0.381
L1.Kärnten -0.013104 0.035784 -0.366 0.714
L1.Niederösterreich -0.032177 0.098349 -0.327 0.744
L1.Oberösterreich 0.304550 0.086368 3.526 0.000
L1.Salzburg 0.017818 0.045540 0.391 0.696
L1.Steiermark 0.005535 0.061574 0.090 0.928
L1.Tirol 0.079458 0.041086 1.934 0.053
L1.Vorarlberg 0.122534 0.037538 3.264 0.001
L1.Wien -0.027763 0.081112 -0.342 0.732
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.135526 0.029861 0.191384 0.251896 0.060694 0.101548 -0.051337 0.169227
Kärnten 0.135526 1.000000 0.010755 0.189252 0.165726 -0.119719 0.149166 0.004308 0.322635
Niederösterreich 0.029861 0.010755 1.000000 0.310023 0.085348 0.219522 0.126644 0.052445 0.355478
Oberösterreich 0.191384 0.189252 0.310023 1.000000 0.298593 0.299186 0.102361 0.078723 0.128338
Salzburg 0.251896 0.165726 0.085348 0.298593 1.000000 0.150095 0.057360 0.090157 -0.010115
Steiermark 0.060694 -0.119719 0.219522 0.299186 0.150095 1.000000 0.105687 0.105637 -0.107076
Tirol 0.101548 0.149166 0.126644 0.102361 0.057360 0.105687 1.000000 0.162944 0.156370
Vorarlberg -0.051337 0.004308 0.052445 0.078723 0.090157 0.105637 0.162944 1.000000 0.035434
Wien 0.169227 0.322635 0.355478 0.128338 -0.010115 -0.107076 0.156370 0.035434 1.000000